package com.hightrast.service.controller;


import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hightrast.service.api.baseEntity.R;
import com.hightrast.service.api.domain.qo.rastUser.QueryRastUserListQo;
import com.hightrast.service.api.domain.vo.rastUser.QueryRastUserInfoVo;
import com.hightrast.service.api.domain.vo.rastUser.QueryRastUserListVo;
import com.hightrast.service.api.entity.RastUser;
import com.hightrast.service.component.MailClient;
import com.hightrast.service.service.IRastUserService;
import com.hightrast.service.util.SecureUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author hx
 * @since 2025-01-11
 */
@RestController
@RequestMapping("/api/rast-user")
@Api(tags = "用户")
public class RastUserController {

    @Resource
    IRastUserService userService;

    @Resource
    MailClient mailClient;

    @ApiOperation("查询 当前 用户信息、角色、菜单、银行账号")
    @GetMapping("/queryCurrentUserInfoRole")
    public R<QueryRastUserInfoVo> queryCurrentUserInfoRole() {
        RastUser user = SecureUtil.getUser();
        return R.data(userService.queryUserInfoRoleById(user.getId()));
    }

    @ApiOperation("查询 指定 用户信息、角色、菜单、银行账号")
    @GetMapping("/queryUserInfoRoleById")
    public R<QueryRastUserInfoVo> queryUserInfoRoleById(@RequestParam("userId") Long userId) {
        return R.data(userService.queryUserInfoRoleById(userId));
    }

    @ApiOperation("查询用户列表")
    @PostMapping("/queryUserList")
    public R<IPage<QueryRastUserListVo>> queryUserList(@RequestBody @Validated QueryRastUserListQo qo) {
        return R.data(userService.queryUserList(qo));
    }

    @ApiOperation("删除指定用户")
    @GetMapping("/deleteUserById")
    public R<Void> deleteUserById(@RequestParam("userId") Long userId) {
        userService.deleteUserById(userId);
        return R.success();
    }

    @ApiOperation("修改指定用户信息")
    @GetMapping("/editUserById")
    public R<Void> editUserById(@RequestParam("userId") Long userId,@RequestParam("userName") String userName) {
        userService.update(new LambdaUpdateWrapper<RastUser>().eq(RastUser::getId,userId).set(RastUser::getUserName,userName));
        return R.success();
    }

    @ApiOperation("查询指定用户信息")
    @GetMapping("/getUserById")
    public R<RastUser> getUserById(@RequestParam("userId") Long userId) {
        return R.data(userService.getById(userId));
    }

    @ApiOperation("获取所有账号邮箱")
    @GetMapping("/queryUserEmail")
    public R<List<String>> queryUserEmail() {
        return R.data(userService.queryUserEmail());
    }

}
